#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/11/17 13:38
# @Author  : yinhai
# @File    : response.py
# @Project : maadaa_data_processing_platform
from rest_framework.views import Response


class APIResponse(Response):
    """
    Class APIResponse

    This class is a subclass of the Response class and represents an API response.

    Attributes:
        code (int): The HTTP status code of the response. Default is 200.
        msg (str): The message associated with the response. Default is None.
        data (dict): The data associated with the response. Default is None.
        status (int): The HTTP status code of the response. Default is None.
        template_name (str): The name of the template to be used for rendering the response. Default is None.
        headers (dict): Additional headers to be included in the response. Default is None.
        exception (bool): Indicates whether an exception occurred. Default is False.
        content_type (str): The content type of the response. Default is None.
        kwargs (dict): Additional keyword arguments to be included in the response.

    Methods:
        __init__: Initializes an instance of the APIResponse class with the specified parameters.

    """
    def __init__(self, code=200, msg=None, data=None, status=None,
                 template_name=None, headers=None,
                 exception=False, content_type=None, **kwargs):

        dic = {'status': code, 'msg': msg}
        if data:
            dic['data'] = data
        if not status:
            status = code
        if kwargs:
            dic.update(**kwargs)

        super().__init__(data=dic, status=status,
                         template_name=template_name, headers=headers,
                         exception=exception, content_type=content_type)
